#ifndef SCOPE_HW_H
#define SCOPE_HW_H

#include "psram.h"

#ifdef __cplusplus
extern "C" {
#endif

#define FAKE_DEBUG               0
#define SCOPE_BYTES_PER_POINT    (7 * 4)

#define HTTP_FS_IV_NUM           1024
#define SCOPE_MAX_SAMPLE_RATE    30000000
#define SCOPE_MIN_SAMPLE_RATE    (PSRAM_MAX_CPU_RATE / 65536 / 2)

#define SCOPE_ADC_SNAP_COUNT     32
#define SCOPE_ADC_BUFFER_POINTS  (SCOPE_ADC_SNAP_COUNT * HTTP_FS_IV_NUM)
#define SCOPE_ADC_BUFFER_WORDS   (SCOPE_ADC_BUFFER_POINTS * sizeof(scope_adc_data) / sizeof(uint32_t))
#define SCOPE_ADC_BUFFER_BYTES   (SCOPE_ADC_BUFFER_WORDS * sizeof(uint32_t))

#define SCOPE_ADC_PIO_INDEX      0
#define SCOPE_ADC_CLK_SM         0 
#define SCOPE_ADC_TO_BUFFER_SM   1
#define SCOPE_ADC_TO_PSRAM_SM    2
#define SCOPE_TRIGGER_SM         3

#define SCOPE_ADC_PIO            INDEX_TO_PIO(SCOPE_ADC_PIO_INDEX)
#define SCOPE_ADC_BUFFER_RX_REQ  INDEX_TO_RX_REQ(SCOPE_ADC_PIO_INDEX, SCOPE_ADC_TO_BUFFER_SM)
#define SCOPE_ADC_PSRAM_RX_REQ   INDEX_TO_RX_REQ(SCOPE_ADC_PIO_INDEX, SCOPE_ADC_TO_PSRAM_SM)
#define SCOPE_TRIGGER_RX_REQ     INDEX_TO_RX_REQ(SCOPE_ADC_PIO_INDEX, SCOPE_TRIGGER_SM)

#define SCOPE_READ_BUFFER_SIZE  128

#define SCOPE_CALI_MAGIC        0x78787788

#define SCOPE_AVG_COUNT         100
#define SCOPE_TIME_DIV_NUM      8
#define SCOPE_DIV_POINT_NUM     (HTTP_FS_IV_NUM / SCOPE_TIME_DIV_NUM)

void scope_hw_init_dma_adc_to_buffer(void);
void scope_hw_set_sample_rate(uint32_t rate);
void scope_hw_set_ch_coupling(int ch, SCOPE_COUPLING coupling);
void scope_hw_set_ch_scale(int ch, int scale);
void scope_hw_update_ch_scale(void);
void scope_hw_auto_ch_scale(void);
void scope_hw_init(void);
void scope_hw_run(void);
void scope_hw_stop(void);
bool scope_hw_psram_finish(void);
uint32_t scope_hw_psram_pos(void);

#ifdef __cplusplus
}
#endif

#endif
